package com.batchengine.rssfeed;

import com.batchengine.db.DBUtils;
import com.batchengine.worker.WorkSelector;
import org.apache.log4j.Logger;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import static com.batchengine.util.LoggingFactory.createLogger;

/**
 * Created by sunil.kalva@mkhoj.com.
 * User: sunilkalva
 * Date: 10 May, 2010
 */
public class RSSFeedSelector extends WorkSelector<List<String>> {

    private static final Logger logger = createLogger();
    final static String sql = "select * from feed where status = 'pending' ";

    public boolean fillWork() throws InterruptedException {
        addToQ(getRSSUrlList());
        return true;
    }


    private List<String> getRSSUrlList() {

        List<String> urlList = new ArrayList<String>();
        try {
            Connection connection = DBUtils.getConnection();
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            if(null != resultSet) {
                while(resultSet.next()) {
                    urlList.add(resultSet.getString("ur"));
                }
            }
            connection.close();
        } catch(Exception e) {
            e.printStackTrace();
        }
        return urlList;
    }

}

